package com.cet.spring_batch_study.jobs.endOfDay;

import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersInvalidException;
import org.springframework.batch.core.JobParametersValidator;

import java.util.Optional;

/**
 * @author NSOC
 */
public class EndOfDayJobParameterValidator implements JobParametersValidator {
    @Override
    public void validate(JobParameters parameters) throws JobParametersInvalidException {
        assert parameters != null;
        long times = Optional.ofNullable(parameters.getLong("loop.times")).orElse(1L);
        if (times <= 0) {
            throw new JobParametersInvalidException("循环次数loop.times必须传入一个大于0的值");
        }
    }
}
